package com.ruoyi.smartcity.huanjing.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.smartcity.huanjing.domain.HuanjingZaosheng;
import com.ruoyi.smartcity.huanjing.service.IHuanjingZaoshengService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 噪声Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/smartcity/huanjing/zaosheng")
public class HuanjingZaoshengController extends BaseController
{
    @Autowired
    private IHuanjingZaoshengService huanjingZaoshengService;

    /**
     * 查询噪声列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HuanjingZaosheng huanjingZaosheng)
    {
        startPage();
        List<HuanjingZaosheng> list = huanjingZaoshengService.selectHuanjingZaoshengList(huanjingZaosheng);
        return getDataTable(list);
    }

    /**
     * 导出噪声列表
     */
    @Log(title = "噪声", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HuanjingZaosheng huanjingZaosheng)
    {
        List<HuanjingZaosheng> list = huanjingZaoshengService.selectHuanjingZaoshengList(huanjingZaosheng);
        ExcelUtil<HuanjingZaosheng> util = new ExcelUtil<HuanjingZaosheng>(HuanjingZaosheng.class);
        util.exportExcel(response, list, "噪声数据");
    }

    /**
     * 获取噪声详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(huanjingZaoshengService.selectHuanjingZaoshengById(id));
    }

    /**
     * 新增噪声
     */
    @Log(title = "噪声", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HuanjingZaosheng huanjingZaosheng)
    {
        return toAjax(huanjingZaoshengService.insertHuanjingZaosheng(huanjingZaosheng));
    }

    /**
     * 修改噪声
     */
    @Log(title = "噪声", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HuanjingZaosheng huanjingZaosheng)
    {
        return toAjax(huanjingZaoshengService.updateHuanjingZaosheng(huanjingZaosheng));
    }

    /**
     * 删除噪声
     */
    @Log(title = "噪声", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(huanjingZaoshengService.deleteHuanjingZaoshengByIds(ids));
    }
}
